﻿// <com.woyouqiu.Copyright>
// --------------------------------------------------------------
// <copyright>上海有求网络科技有限公司 2015</copyright>
// <Solution>MyCompany.MyProject</Solution>
// <Project>MyCompany.MyProject.Application</Project>
// <FileName>Coordinate.cs</FileName>
// <CreateTime>2017-04-23 17:10</CreateTime>
// <Author>何苗</Author>
// <Email>hemiao@woyouqiu.com</Email>
// <log date="2017-04-23 17:10" version="00001">创建</log>
// --------------------------------------------------------------
// </com.woyouqiu.Copyright>
namespace Vecen.BangChuang.BangChuang.Areas.Dtos {
    /// <summary>
    /// 经纬度
    /// </summary>
    public class Coordinate {

        /// <summary>
        /// 
        /// </summary>
        public Coordinate() { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <param name="coordinateSystem"></param>
        public Coordinate(double latitude, double longitude, CoordinateSystem coordinateSystem) {
            Longitude = longitude;
            Latitude = latitude;
            CoordinateSystem = coordinateSystem;
        }

        /// <summary>
        /// 经度
        /// </summary>
        public double Longitude { get; set; }

        /// <summary>
        /// 纬度
        /// </summary>
        public double Latitude { get; set; }

        /// <summary>
        /// 坐标类型
        /// </summary>

        public CoordinateSystem CoordinateSystem { get; set; }

        /// <summary>
        /// 经度,纬度
        /// </summary>
        /// <returns></returns>
        public override string ToString() {
            return Longitude + "," + Latitude;
        }

        /// <summary>
        /// 根据传入类型转换坐标
        /// </summary>
        /// <param name="coordinateSystem"></param>
        /// <returns></returns>
        public string ToString(CoordinateSystem coordinateSystem) {
            CoordinateTransform coordinateTransform = new CoordinateTransform();
            switch(coordinateSystem) {
                case CoordinateSystem.BD_09:
                    switch(CoordinateSystem) {
                        case CoordinateSystem.GCJ_02:
                            return coordinateTransform.Gcj02_To_Bd09(Latitude, Longitude).ToString();
                        case CoordinateSystem.WGS84:
                            return coordinateTransform.Gcj02_To_Bd09(Latitude, Longitude).ToString();
                        case CoordinateSystem.BD_09: return ToString();
                        default: return ToString();
                    }
                case CoordinateSystem.GCJ_02:
                    switch(CoordinateSystem) {
                        case CoordinateSystem.GCJ_02: return ToString();
                        case CoordinateSystem.WGS84:
                            return coordinateTransform.Gps84_To_Gcj02(Latitude, Longitude).ToString();
                        case CoordinateSystem.BD_09:
                            return coordinateTransform.Bd09_To_Gcj02(Latitude, Longitude).ToString();
                        default: return ToString();
                    }
                case CoordinateSystem.WGS84:
                    switch(CoordinateSystem) {
                        case CoordinateSystem.GCJ_02:
                            return coordinateTransform.Gcj_To_Gps84(Latitude, Longitude).ToString();
                        case CoordinateSystem.WGS84: return ToString();
                        case CoordinateSystem.BD_09:
                            return coordinateTransform.Bd09_To_Gps84(Latitude, Longitude).ToString();
                        default: return ToString();
                    }
                default: return ToString();
            }
        }
    }

    /// <summary>
    /// 坐标系
    /// </summary>
    public enum CoordinateSystem {

        /// <summary>
        /// 地心坐标 
        /// <remarks>
        ///（1）谷歌国外地图
        ///（2）osm地图
        /// </remarks>
        /// </summary>
        WGS84 = 0,

        /// <summary>
        /// 火星坐标
        /// <remarks>
        ///（1）iOS 地图
        ///（2）Gogole map地图
        ///（3）搜搜地图
        ///（4）阿里云
        ///（5）高德地图
        /// </remarks>
        /// </summary>
        GCJ_02 = 1,

        /// <summary>
        /// 百度坐标
        /// <remarks>
        /// （1）百度地图
        /// </remarks>
        /// </summary>
        BD_09 = 2
    }
}